﻿<%@ WebHandler Language="C#" Class="AjaxSubmitFlag" %>

using System;
using System.Web;
using System.Data;

public class AjaxSubmitFlag : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        //string strFlowName = context.Server.UrlDecode(context.Request["dataFlowname"]);
        string strFlowName = context.Server.UrlDecode(Common.Encode.DESDecrypt(context.Request["dataFlowname"]));
        string strUserID = context.Request["userId"];
        string strIID = context.Request["dataIId"];

        //先处理iid的问题
        ChBusiness.Wsbs.ShenBaoSubmit submit = new ChBusiness.Wsbs.ShenBaoSubmit();
        int nReturnSubmit = submit.InsertSubmitInfo(strIID, strFlowName, strUserID);

        //Common.Log.LogManage.addLogErr("提交监控流程编码",strIID+" "+strFlowName);
        context.Response.Write(PostIId(strIID, strFlowName));
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    /// <summary>
    /// 提交并设置状态位
    /// </summary>
    /// <param name="strIId"></param>
    /// <param name="strFlowname">办理事项名称</param>
    /// <param name="strUserID"></param>
    /// <param name="strUserName"></param>
    /// <param name="strBgFlag">变更标志</param>
    /// <param name="strFlowType">办理事项分类</param>
    /// <returns></returns>
    public string PostIId(string strIId, string strFlowname)
    {
        ChBusiness.Wsbs.ShenBaoSubmit submit = new ChBusiness.Wsbs.ShenBaoSubmit();
        string strFlag = submit.GetFlag(strFlowname);
        if (strFlag == "1")//判断是否所有附件均以上传
        {
            ChBusiness.CommonBusiness.UploadFileClass upload = new ChBusiness.CommonBusiness.UploadFileClass();

            string strAlredyCount = upload.GetAlreadyUpdateCount(strIId, strFlowname);
            string strCount = upload.GetUpdateCount(strFlowname);
            if (strAlredyCount != strCount)
            {
                return "";
            }
        }

        string strMsg = submit.GetBtx(strFlowname, strIId);
        if (!string.IsNullOrEmpty(strMsg))//判断是否所有必填项都已经填写
        {
            return strMsg;
        }

        int nReturn = 0;
        nReturn = submit.UpdateSubmit(strIId, 1);

        if (nReturn == 1)
        {
            return "提交成功";
        }

        return "";
    }
}